import java.util.Arrays;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User:
 * Date: 2024-08-24
 * Time: 17:24
 */
public class MyStack {
    public int[] elem;
    public int useSize;

    public MyStack(){
        this.elem = new int[10];
    }
    public void push(int val){
        if(isFull()){
            elem = Arrays.copyOf(elem,2*elem.length);
        }
        elem[useSize] = val;
        useSize++;
    }
    private boolean isFull(){
        return useSize == elem.length;
    }

    public int pop(){
        if(isEmpty()){
            throw new CheckEmptyExpetion("栈为空");
        }
        int cur = elem[useSize-1];
        useSize--;
        return cur;
    }

    public int peek(){
        if(isEmpty()){
            throw new CheckEmptyExpetion("栈为空");
        }
        int cur = elem[useSize-1];
        return cur;
    }

    private boolean isEmpty(){
        return useSize == 0;
    }

    public int size(){
        return useSize;
    }
}
